package com.shg.admin.acutuator.health;

import com.shg.admin.component.MyHahaComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MyHahaHealthIndicator extends AbstractHealthIndicator {

    @Autowired
    private MyHahaComponent myHahaComponent;

    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        int checkResult = myHahaComponent.check();
        Map<String, Object> map = new HashMap<>();
        if (checkResult == 1) {
            builder.up().build();
            map.put("msg", "组件状态正常");
        } else {
            builder.down().build();
            builder.up().build();
            map.put("msg", "组件状态异常");
        }
        builder.withDetails(map);
    }
}
